package com.its.common.util;

import com.alibaba.fastjson.JSONObject;

import static com.its.common.constant.GeoRoute.*;

/**
 * @Author zhuys
 * @Date 2020/3/25 17:10
 * @Description
 */
public class GeoTransUtil {

    public static String geoTrans(String wkt, String route) {
        String routeParam = "";
        String resp = "";
        switch (route.toLowerCase()) {
            case WGS2SZ://wgs84->suzhou
                routeParam = WGS2SZ;
                break;
            case WGS2GCJ:
                routeParam = WGS2GCJ;
                break;
            case WGS2BD:
                routeParam = WGS2BD;
                break;
            case SZ2WGS:
                routeParam = SZ2WGS;
                break;
            case SZ2D225D:
                routeParam = SZ2D225D;
                break;
            case SZ2BD:
                routeParam = SZ2BD;
                break;
            case SZ2GCJ:
                routeParam = SZ2GCJ;
                break;
            case GCJ2WGS:
                routeParam = GCJ2WGS;
                break;
            case GCJ2SZ:
                routeParam = GCJ2SZ;
                break;
            case GCJ2BD:
                routeParam = GCJ2BD;
                break;
            case BD2WGS:
                routeParam = BD2WGS;
                break;
            case BD2SZ:
                routeParam = BD2SZ;
                break;
            case BD2GCJ:
                routeParam = BD2GCJ;
                break;
                default:
                    break;
        }

        JSONObject params = new JSONObject();
        params.put("wkt", wkt.replace(" ","%20"));
        params.put("route", routeParam);
      //  String url = host + routeParam;
        resp= HttpUtils.postData(host, params);
        return resp;
    }

    /**
     * 坐标点转化
     * @param point
     * @param type
     * @return
     */
    public static String changePoint(String point, String type) {
        String geoPoint = "Point(" + point + ")";
        String resultS = GeoTransUtil.geoTrans(geoPoint, type);
        String shapeS = JSONObject.parseObject(resultS).getJSONObject("msg").getString("results");
        String substring = shapeS.substring(6, shapeS.length() - 1).replace(" ", ",");
        return substring;
    }

    /**
     *  坐标线转化
     * @param line
     * @param type
     * @return
     */
    public static String changeLine(String line, String type) {
        String geoPoint = "LINESTRING(" + line + ")";
        String resultS = GeoTransUtil.geoTrans(geoPoint, type);
        String shapeS = JSONObject.parseObject(resultS).getJSONObject("msg").getString("results");
        String substring = shapeS.substring(6, shapeS.length() - 1).replace(" ", ",");
        return substring;
    }


    public static String geoTransResult(String line, String type) {
        String resultS = GeoTransUtil.geoTrans(line, type);
        String shapeS = JSONObject.parseObject(resultS).getJSONObject("msg").getString("results");
        return shapeS;
    }



   /*public static void main(String[] args) {
        String wktLine = "LINESTRING(63949.958711 36397.721359,63914.41820 36383.81058)";
        String wktPoint = "Point(120.764869689941 31.3260612487793)";
        String wktPoint2 = "Point(120.726466570375 31.2369102102576)";

   //     String lineRes = geoTrans(wktLine,SZ2GCJ);
        String pointRes = geoTrans(wktPoint,GCJ2SZ);
  //      String point2Res = geoTrans(wktPoint2,GCJ2SZ);
 //       System.out.println("line:"+lineRes);
        System.out.println("point:"+pointRes);
//        System.out.println("point2:"+point2Res);
    }*/

}
